//author:kakake
/**
 * 医生评价处理
 */
class tsevaluationController {
    public data = {
        dbConn: TSLobsterAPI.Program.GetDbConn(),
        WorkId: 1
    }

    public service: tsevaluationService;
    public dao: tsevaluationDao;

    constructor() {
        this.data.WorkId = TSLobsterAPI.Program.GetWorkId();

        this.service = new tsevaluationService(this.data.WorkId);
        this.dao = new tsevaluationDao(this.data.WorkId);

    }

    /**
     * 获取问诊记录
     */
    getmedrecord() {
        let id = TSLobsterAPI.Program.RequestQuery("id") || '0';
        let data = this.dao.getmedrecord(parseInt(id));
        return { info: data };
    }

    /**
     * 获取评价
     */
    getevaluation() {
        let RecordId = TSLobsterAPI.Program.RequestQuery("RecordId") || '0';
        let data = this.dao.getevaluation(parseInt(RecordId));
        return { evaluation: data };
    }

    /**
     * 提交评价
     */
    saveevaluation() {
        var model = JSON.parse(TSLobsterAPI.Program.RequestBody());
        let evaluation = new WPMT_DoctorEvaluation_ORM(this.data.WorkId);
        var evaluationVal: WPMT_DoctorEvaluation_Model = <WPMT_DoctorEvaluation_Model>{};
        evaluationVal.ID = model.ID;
        evaluationVal.RecordId = model.RecordId;
        evaluationVal.OrderNo = model.OrderNo;
        evaluationVal.MPUserId = TSLobsterAPI.Program.GetMPUserId();
        evaluationVal.EmpId = model.EmpId;
        evaluationVal.PatientId = model.PatientId;
        evaluationVal.Satisfaction = model.Satisfaction;
        evaluationVal.EvaluateContent = model.EvaluateContent;
        evaluationVal.Status = 0;
        evaluationVal.EvaluateTime = TSLobsterAPI.Utils.getCurrTime();
        evaluationVal.OperateTime = TSLobsterAPI.Utils.getCurrTime();
        evaluationVal.ReplyContent = "";
        evaluationVal.ReplyEmpId = 0;
        evaluationVal.ReplyTime = null;
        evaluationVal.DocName = model.DocName;
        evaluationVal.PatName = model.PatName;

        evaluation.Save(evaluationVal);

        return { result: true };
    }

    /**
     * 获取待处理评价
     */
    getevaluationpage() {
        var pageInfo = {
            key: "ID",
            page: TSLobsterAPI.Program.RequestQuery("page", "1"),
            perPage: TSLobsterAPI.Program.RequestQuery("limit", "10"),
            totalRecord: 100
        };

        let searchkey = TSLobsterAPI.Program.RequestQuery("searchkey") || '';
        let status = TSLobsterAPI.Program.RequestQuery("status") || '-1';
        var data = this.dao.getevaluationpage(searchkey, parseInt(status), pageInfo);
        return { data: data, count: pageInfo.totalRecord };
    }

    /**
     * 医生信息界面，显示点赞最多的评价
     */
    getevaluationtopone() {
        let doctId = TSLobsterAPI.Program.RequestQuery("doctId");
        var data = this.dao.getevaluationtopone(doctId);
        return { data: data };
    }

    /**
     * 查询医生全部评价
     */
    getevaluationbydoctor() {
        var pageInfo = {
            key: "ID desc",
            page: TSLobsterAPI.Program.RequestQuery("page", "1"),
            perPage: TSLobsterAPI.Program.RequestQuery("perPage", "5"),
            totalRecord: 100
        };
        let doctId = TSLobsterAPI.Program.RequestQuery("doctId");
        var data = this.dao.getevaluationbydoctor(doctId, pageInfo);
        return { data: data, count: pageInfo.totalRecord };
    }

    /**
     * 保存回复内容
     */
    savereplycontent() {
        var model = JSON.parse(TSLobsterAPI.Program.RequestBody());
        this.dao.savereplycontent(model.ID, model.ReplyContent);
        return { result: true };
    }

    /**
     * 删除回复内容
     */
    deletereplycontent() {
        let id = TSLobsterAPI.Program.RequestQuery("ID") || '0';
        this.dao.savereplycontent(id, null);
        return { result: true };
    }

    /**
     * 发布，取消发布
     */
    stopevaluation() {
        let id = TSLobsterAPI.Program.RequestQuery("id") || '0';
        let status = TSLobsterAPI.Program.RequestQuery("status") || '0';

        this.dao.stopevaluation(id, status);
        return { result: true };
    }

    /**
     * 更新评价点赞数
     */
    updateevaluationgivecount() {
        let id = TSLobsterAPI.Program.RequestQuery("id");
        let givecount = this.dao.updateevaluationgivecount(id);
        return { result: true, givecount: givecount };
    }

}